package com.zh.yqbj.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import com.zh.yqbj.VO.UserVO;
import com.zh.yqbj.entity.*;
import com.zh.yqbj.mapper.UserMapper;
import com.zh.yqbj.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zh
 * @since 2024-03-19 07:46:31
 */
@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public UserVO getLoginUserInfo() {
        //没登陆过返回空
        if(!StpUtil.isLogin()) {
            return new UserVO();
        }
        String id = StpUtil.getLoginIdAsString();
        User user = this.getById(id);
        UserVO userVO = BeanUtil.copyProperties(user, UserVO.class);
        List<String> roleList = StpUtil.getRoleList(id);
        userVO.setRoleList(roleList);
        return userVO;
    }
}
